Skip to content

Commit

Permalink
Grading report - columns sorting support
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Jan 4, 2010
1 parent ff41eb7 commit d10ee0b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 21 deletions.
16 changes: 8 additions & 8 deletions mod/workshop/lang/en_utf8/workshop.php
Expand Up @@ -30,13 +30,10 @@
$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';
Expand Down Expand Up @@ -86,10 +83,11 @@
$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';
Expand All @@ -113,6 +111,7 @@
$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';
Expand Down Expand Up @@ -140,6 +139,7 @@
$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';
Expand Down
92 changes: 83 additions & 9 deletions mod/workshop/renderer.php
Expand Up @@ -402,25 +402,38 @@ protected function user_plan_tasks(array $tasks) {
* @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;

if (empty($grades)) {
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();
Expand Down Expand Up @@ -508,6 +521,50 @@ public function grading_report(stdClass $data, $showauthornames, $showreviewerna
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
Expand Down Expand Up @@ -621,4 +678,21 @@ protected static function array_nth(array $a, $n) {
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';
}
}

}
8 changes: 4 additions & 4 deletions mod/workshop/view.php
Expand Up @@ -158,11 +158,11 @@
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);
Expand Down Expand Up @@ -194,7 +194,7 @@
$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;
Expand Down

0 comments on commit d10ee0b

Please sign in to comment.