]> git.mjollnir.org Git - moodle.git/commitdiff
Grading report - columns sorting support
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:13:04 +0000 (18:13 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:13:04 +0000 (18:13 +0000)
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/renderer.php
mod/workshop/view.php

index 53a3a57496a5dc51531c83de8fef2998fbb2ed75..66e63404376b7b8fc29e59fe8e270871250fc4a5 100644 (file)
@@ -30,13 +30,10 @@ $string[''] = '';
 $string[''] = '';
 $string[''] = '';
 $string[''] = '';
-$string['aggregationinfo'] = 'During the aggregation process, the grades for submission, grades for assessment and total grades are re-calculated and stored into the Workshop database. This does not modify any manual overrides nor does not push the total grade into the gradebook.';
-$string['aggregation'] = 'Grades aggregation';
-$string['aggregategrades'] = 'Re-calculate grades';
-$string['nullgrade'] = '?';
-$string['formatpeergradeover'] = '$a->grade (<del>$a->gradinggrade</del> / <ins>$a->gradinggradeover</ins>)';
-$string['formatpeergrade'] = '$a->grade ($a->gradinggrade)';
 $string['accesscontrol'] = 'Access control';
+$string['aggregategrades'] = 'Re-calculate grades';
+$string['aggregation'] = 'Grades aggregation';
+$string['aggregationinfo'] = 'During the aggregation process, the grades for submission, grades for assessment and total grades are re-calculated and stored into the Workshop database. This does not modify any manual overrides nor does not push the total grade into the gradebook.';
 $string['agreeassessments'] = 'Assessments must be agreed';
 $string['agreeassessmentsdesc'] = 'Authors may comment assessments of their work and agree/disagree with it';
 $string['allocate'] = 'Allocate submissions';
@@ -86,10 +83,11 @@ $string['examplesbeforeassessment'] = 'Examples are available after own submissi
 $string['examplesbeforesubmission'] = 'Examples must be assessed before own submission';
 $string['examplesmode'] = 'Mode of examples assessment';
 $string['examplesvoluntary'] = 'Assessment of example submission is voluntary';
+$string['formatpeergrade'] = '$a->grade ($a->gradinggrade)';
+$string['formatpeergradeover'] = '$a->grade (<del>$a->gradinggrade</del> / <ins>$a->gradinggradeover</ins>)';
 $string['givengrade'] = 'Given grade: $a';
 $string['givengrades'] = 'Given grades';
-$string['gradeforassessment'] = 'Grade for assessment';
-$string['gradeforsubmission'] = 'Grade for submission';
+$string['gradinggrade'] = 'Grade for assessment';
 $string['gradingsettings'] = 'Grading settings';
 $string['chooseuser'] = 'Choose user...';
 $string['iamsure'] = 'Yes, I am sure';
@@ -113,6 +111,7 @@ $string['nothingtoreview'] = 'Nothing to review';
 $string['noworkshops'] = 'There are no workshops in this course';
 $string['noyoursubmission'] = 'You have not submitted your work yet';
 $string['nsassessments'] = 'Number of required assessments of other users\' work';
+$string['nullgrade'] = '?';
 $string['numofreviews'] = 'Number of reviews';
 $string['participant'] = 'Participant';
 $string['participantrevierof'] = 'Participant is reviewer of';
@@ -140,6 +139,7 @@ $string['strategyrubric'] = 'Rubric grading';
 $string['submissionattachment'] = 'Attachment';
 $string['submissioncontent'] = 'Submission content';
 $string['submissionend'] = 'End of submission phase';
+$string['submissiongrade'] = 'Grade for submission';
 $string['submissionsettings'] = 'Submission settings';
 $string['submissionstart'] = 'Start of submission phase';
 $string['submission'] = 'Submission';
index a57a412fa7af967b46e214c014ae6e43e19beb02..e723aed87c1bb7a9a8fa6da203275064ed1f33e8 100644 (file)
@@ -402,9 +402,11 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
      * @param stdClass $data prepared by {@link workshop::prepare_grading_report()}
      * @param bool $showauthornames
      * @param bool $showreviewernames
+     * @param string $sortby
+     * @param string $sorthow
      * @return string html code
      */
-    public function grading_report(stdClass $data, $showauthornames, $showreviewernames) {
+    public function grading_report(stdClass $data, $showauthornames, $showreviewernames, $sortby, $sorthow) {
         $grades = $data->grades;
         $userinfo = $data->userinfo;
 
@@ -412,15 +414,26 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
             return '';
         }
 
-        $table              = new html_table();
+        $table = new html_table();
         $table->set_classes('grading-report');
-        $table->head        = array(get_string('participant', 'workshop'),
-                                    get_string('submission', 'workshop'),
-                                    get_string('receivedgrades', 'workshop'),
-                                    get_string('gradeforsubmission', 'workshop'),
-                                    get_string('givengrades', 'workshop'),
-                                    get_string('gradeforassessment', 'workshop'),
-                                    get_string('totalgrade', 'workshop'));
+
+        $sortbyfirstname = $this->sortable_heading(get_string('firstname'), 'firstname', $sortby, $sorthow);
+        $sortbylastname = $this->sortable_heading(get_string('lastname'), 'lastname', $sortby, $sorthow);
+        if (self::fullname_format() == 'lf') {
+            $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
+        } else {
+            $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
+        }
+
+        $table->head = array(
+                $sortbyname,
+                $this->sortable_heading(get_string('submission', 'workshop'), 'submissiontitle', $sortby, $sorthow),
+                $this->sortable_heading(get_string('receivedgrades', 'workshop')),
+                $this->sortable_heading(get_string('submissiongrade', 'workshop'), 'submissiongrade', $sortby, $sorthow),
+                $this->sortable_heading(get_string('givengrades', 'workshop')),
+                $this->sortable_heading(get_string('gradinggrade', 'workshop'), 'gradinggrade', $sortby, $sorthow),
+                $this->sortable_heading(get_string('totalgrade', 'workshop'), 'totalgrade', $sortby, $sorthow),
+            );
         $table->rowclasses  = array();
         $table->colclasses  = array('reviewedby', 'peer', 'reviewerof');
         $table->data        = array();
@@ -508,6 +521,50 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
         return $this->output->table($table);
     }
 
+    /**
+     * Renders a text with icons to sort by the given column
+     *
+     * This is intended for table headings.
+     *
+     * @param string $text    The heading text
+     * @param string $sortid  The column id used for sorting
+     * @param string $sortby  Currently sorted by (column id)
+     * @param string $sorthow Currently sorted how (ASC|DESC)
+     *
+     * @return string
+     */
+    protected function sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
+        global $PAGE;
+
+        $out = $this->output->output_tag('span', array('class'=>'text'), $text);
+
+        if (!is_null($sortid)) {
+            $iconasc = new moodle_action_icon();
+            $iconasc->image->src = $this->old_icon_url('t/down');
+            $iconasc->image->alt = get_string('sortasc', 'workshop');
+            $iconasc->image->set_classes('sort asc');
+            $newurl = clone($PAGE->url);
+            $newurl->params(array('sortby' => $sortid, 'sorthow' => 'ASC'));
+            $iconasc->link->url = new moodle_url($newurl);
+
+            $icondesc = new moodle_action_icon();
+            $icondesc->image->src = $this->old_icon_url('t/up');
+            $icondesc->image->alt = get_string('sortdesc', 'workshop');
+            $icondesc->image->set_classes('sort desc');
+            $newurl = clone($PAGE->url);
+            $newurl->params(array('sortby' => $sortid, 'sorthow' => 'DESC'));
+            $icondesc->link->url = new moodle_url($newurl);
+
+            if ($sortby !== $sortid or $sorthow !== 'ASC') {
+                $out .= $this->output->action_icon($iconasc);
+            }
+            if ($sortby !== $sortid or $sorthow !== 'DESC') {
+                $out .= $this->output->action_icon($icondesc);
+            }
+        }
+        return $out;
+}
+
     /**
      * @param stdClass $participant
      * @param array $userinfo
@@ -621,4 +678,21 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
         return $a[$key];
     }
 
+    /**
+     * Tries to guess the fullname format set at the site
+     *
+     * @return string fl|lf
+     */
+    protected static function fullname_format() {
+        $fake = new stdClass(); // fake user
+        $fake->lastname = 'LLLL';
+        $fake->firstname = 'FFFF';
+        $fullname = get_string('fullnamedisplay', '', $fake);
+        if (strpos($fullname, 'LLLL') < strpos($fullname, 'FFFF')) {
+            return 'lf';
+        } else {
+            return 'fl';
+        }
+    }
+
 }
index 366a916e6d73e72e1d7643556f648e0b1cb38af4..e6aec417ef298044ccea727a63902fc850eb22e8 100644 (file)
@@ -158,11 +158,11 @@ case workshop::PHASE_ASSESSMENT:
 case workshop::PHASE_EVALUATION:
     $pagingvar  = 'page';
     $page       = optional_param($pagingvar, 0, PARAM_INT);
+    $sortby     = optional_param('sortby', 'lastname', PARAM_ALPHA);
+    $sorthow    = optional_param('sorthow', 'ASC', PARAM_ALPHA);
+
     $perpage    = 10;           // todo let the user modify this
     $groups     = '';           // todo let the user choose the group
-    $sortby     = 'submissiongrade';   // todo let the user choose the column to sort by
-    $sorthow    = 'ASC';        // todo detto
-
     $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
     if ($data) {
         $showauthornames    = has_capability('mod/workshop:viewauthornames', $PAGE->context);
@@ -194,7 +194,7 @@ case workshop::PHASE_EVALUATION:
         $pagingbar->pagevar     = $pagingvar;
 
         echo $OUTPUT->paging_bar($pagingbar);
-        echo $wsoutput->grading_report($data, $showauthornames, $showreviewernames);
+        echo $wsoutput->grading_report($data, $showauthornames, $showreviewernames, $sortby, $sorthow);
         echo $OUTPUT->paging_bar($pagingbar);
     }
     break;