From: David Mudrak Date: Mon, 4 Jan 2010 18:08:27 +0000 (+0000) Subject: MDL-20058 first prototype of the grading report renderer X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=29dc43e7e4849af3aa9875c0f0f0a550dbfc0c1d;p=moodle.git MDL-20058 first prototype of the grading report renderer --- diff --git a/mod/workshop/allocation/manual/lib.php b/mod/workshop/allocation/manual/lib.php index 4b4c8707cb..74b818b6e7 100644 --- a/mod/workshop/allocation/manual/lib.php +++ b/mod/workshop/allocation/manual/lib.php @@ -210,7 +210,7 @@ class workshop_manual_allocator implements workshop_allocator { $userinfo = $DB->get_records_list('user', 'id', array_keys($participants), '', 'id,lastname,firstname,picture,imagealt'); // load the participants' submissions - $submissions = $this->workshop->get_submissions(array_keys($participants), false); + $submissions = $this->workshop->get_submissions(array_keys($participants)); foreach ($submissions as $submission) { if (!isset($userinfo[$submission->authorid])) { $userinfo[$submission->authorid] = new stdClass(); @@ -257,7 +257,7 @@ class workshop_manual_allocator implements workshop_allocator { JOIN {workshop_assessments} a ON (a.reviewerid = u.id) JOIN {workshop_submissions} s ON (a.submissionid = s.id) JOIN {user} e ON (s.authorid = e.id) - WHERE u.id $participantids AND s.workshopid = :workshopid"; + WHERE u.id $participantids AND s.workshopid = :workshopid AND s.example = 0"; $reviewees = $DB->get_records_sql($sql, $params); foreach ($reviewees as $reviewee) { if (!isset($userinfo[$reviewee->revieweeid])) { @@ -314,7 +314,6 @@ class workshop_manual_allocator implements workshop_allocator { $pagingbar->perpage = workshop::PERPAGE; $pagingbar->baseurl = $PAGE->url; $pagingbar->pagevar = $pagingvar; - $pagingbar->nocurr = true; $pagingbarout = $OUTPUT->paging_bar($pagingbar); diff --git a/mod/workshop/allocation/manual/renderer.php b/mod/workshop/allocation/manual/renderer.php index c5f1820f31..d52ea17b53 100644 --- a/mod/workshop/allocation/manual/renderer.php +++ b/mod/workshop/allocation/manual/renderer.php @@ -64,7 +64,7 @@ class moodle_workshopallocation_manual_renderer extends moodle_renderer_base { $selfassessment = $data->selfassessment; // bool is the self-assessment allowed in this workshop? if (empty($allocations)) { - return $this->output->heading(get_string('nosubmissions', 'workshop')); + return ''; } // convert user collections into drop down menus diff --git a/mod/workshop/allocation/random/lib.php b/mod/workshop/allocation/random/lib.php index 021754a89a..16f17eb68f 100644 --- a/mod/workshop/allocation/random/lib.php +++ b/mod/workshop/allocation/random/lib.php @@ -230,7 +230,7 @@ class workshop_random_allocator implements workshop_allocator { $newallocations = $this->get_unique_allocations($newallocations); $authorids = $this->get_author_ids($newallocations); - $submissions = $this->workshop->get_submissions($authorids, false); + $submissions = $this->workshop->get_submissions($authorids); $submissions = $this->index_submissions_by_authors($submissions); foreach ($newallocations as $newallocation) { list($reviewerid, $authorid) = each($newallocation); diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index 6969e0eb4c..50d6d2f8ef 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -27,6 +27,10 @@ defined('MOODLE_INTERNAL') || die(); $string[''] = ''; $string[''] = ''; +$string[''] = ''; +$string['null'] = '?'; +$string['formatpeergradeover'] = '$a->grade ($a->gradinggrade / $a->gradinggradeover)'; +$string['formatpeergrade'] = '$a->grade ($a->gradinggrade)'; $string['accesscontrol'] = 'Access control'; $string['agreeassessments'] = 'Assessments must be agreed'; $string['agreeassessmentsdesc'] = 'Authors may comment assessments of their work and agree/disagree with it'; @@ -78,6 +82,7 @@ $string['examplesbeforesubmission'] = 'Examples must be assessed before own subm $string['examplesmode'] = 'Mode of examples assessment'; $string['examplesvoluntary'] = 'Assessment of example submission is voluntary'; $string['givengrade'] = 'Given grade: $a'; +$string['givengrades'] = 'Given grades'; $string['gradeforassessment'] = 'Grade for assessment'; $string['gradeforsubmission'] = 'Grade for submission'; $string['gradingsettings'] = 'Grading settings'; @@ -114,6 +119,7 @@ $string['phasesetup'] = 'Setup phase'; $string['phasesubmission'] = 'Submission phase'; $string['previewassessmentform'] = 'Preview'; $string['reassess'] = 'Re-assess'; +$string['receivedgrades'] = 'Received grades'; $string['releasegrades'] = 'Push final grades into the gradebook'; $string['saveandclose'] = 'Save and close'; $string['saveandcontinue'] = 'Save and continue editing'; @@ -148,6 +154,7 @@ $string['taskinstructreviewers'] = 'Provide instructions for assessing'; $string['taskintro'] = 'Set the workshop introduction'; $string['tasksubmit'] = 'Submit your work'; $string['teacherweight'] = 'Weight of the teacher\'s assessments'; +$string['totalgrade'] = 'Total grade'; $string['undersetup'] = 'The workshop is currently under setup. Please wait until it is switched to the next phase.'; $string['useexamplesdesc'] = 'Users practise evaluating on example submissions'; $string['useexamples'] = 'Use examples'; diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 08baea4ea7..db458bffa0 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -31,6 +31,7 @@ defined('MOODLE_INTERNAL') || die(); require_once(dirname(__FILE__).'/lib.php'); // we extend this library here +require_once($CFG->libdir . '/gradelib.php'); /** * Full-featured workshop API @@ -244,10 +245,9 @@ class workshop { * tables. Does not return textual fields to prevent possible memory lack issues. * * @param mixed $authorid int|array|'all' If set to [array of] integer, return submission[s] of the given user[s] only - * @param mixed $examples false|true|'all' Only regular submissions, only examples, all submissions * @return array */ - public function get_submissions($authorid='all', $examples=false) { + public function get_submissions($authorid='all') { global $DB; $sql = 'SELECT s.id, s.workshopid, s.example, s.authorid, s.timecreated, s.timemodified, @@ -258,20 +258,10 @@ class workshop { t.picture AS overpicture, t.imagealt AS overimagealt FROM {workshop_submissions} s INNER JOIN {user} u ON (s.authorid = u.id) - LEFT JOIN {user} t ON (s.gradeoverby = u.id) - WHERE s.workshopid = :workshopid'; + LEFT JOIN {user} t ON (s.gradeoverby = t.id) + WHERE s.example = 0 AND s.workshopid = :workshopid'; $params = array('workshopid' => $this->id); - if ('all' === $examples) { - // no additional conditions - } elseif ($examples === true) { - $sql .= ' AND example = 1'; - } elseif ($examples === false) { - $sql .= ' AND example = 0'; - } else { - throw new coding_exception('Illegal parameter value: $examples may be false|true|"all"'); - } - if ('all' === $authorid) { // no additional conditions } elseif (is_array($authorid)) { @@ -296,6 +286,8 @@ class workshop { public function get_submission_by_id($id) { global $DB; + // we intentionally check the workshopid here, too, so the workshop can't touch submissions + // from other instances $sql = 'SELECT s.*, u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid, u.picture AS authorpicture, u.imagealt AS authorimagealt @@ -917,6 +909,227 @@ class workshop { return $grade; } + /** + * Prepares data object with all workshop grades to be rendered + * + * @todo this is very similar to what allocation/manual/lib.php does - refactoring expectable + * @param stdClass $context of the workshop instance + * @param int $userid + * @param int $page the current page (for the pagination) + * @return stdClass data for the renderer + */ + public function prepare_grading_report(stdClass $context, $userid, $page) { + global $DB; + + $canviewall = has_capability('mod/workshop:viewallassessments', $context, $userid); + $isparticipant = has_any_capability(array('mod/workshop:submit', 'mod/workshop:peerassess'), $context, $userid); + + if (!$canviewall and !$isparticipant) { + // who the hell is this? + return array(); + } + + if ($canviewall) { + // fetch the list of ids of all workshop participants - this may get really long so fetch just id + $participants = get_users_by_capability($context, array('mod/workshop:submit', 'mod/workshop:peerassess'), + 'u.id', 'u.lastname,u.firstname,u.id', '', '', '', '', false, false, true); + } else { + // this is an ordinary workshop participant (aka student) - display the report just for him/her + $participants = array($userid => (object)array('id' => $userid)); + } + + // we will need to know the number of all later for the pagination purposes + $numofparticipants = count($participants); + + // slice the list of participants according to the current page + $participants = array_slice($participants, $page * self::PERPAGE, self::PERPAGE, true); + + // this will hold the information needed to display user names and pictures + $userinfo = $DB->get_records_list('user', 'id', array_keys($participants), '', 'id,lastname,firstname,picture,imagealt'); + + // load the participants' submissions + $submissions = $this->get_submissions(array_keys($participants)); + foreach ($submissions as $submission) { + if (!isset($userinfo[$submission->authorid])) { + $userinfo[$submission->authorid] = new stdClass(); + $userinfo[$submission->authorid]->id = $submission->authorid; + $userinfo[$submission->authorid]->firstname = $submission->authorfirstname; + $userinfo[$submission->authorid]->lastname = $submission->authorlastname; + $userinfo[$submission->authorid]->picture = $submission->authorpicture; + $userinfo[$submission->authorid]->imagealt = $submission->authorimagealt; + } + if (!isset($userinfo[$submission->gradeoverby])) { + $userinfo[$submission->gradeoverby] = new stdClass(); + $userinfo[$submission->gradeoverby]->id = $submission->gradeoverby; + $userinfo[$submission->gradeoverby]->firstname = $submission->overfirstname; + $userinfo[$submission->gradeoverby]->lastname = $submission->overlastname; + $userinfo[$submission->gradeoverby]->picture = $submission->overpicture; + $userinfo[$submission->gradeoverby]->imagealt = $submission->overimagealt; + } + } + + // get current reviewers + $reviewers = array(); + if ($submissions) { + list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED); + $sql = "SELECT a.id AS assessmentid, a.submissionid, a.grade, a.gradinggrade, a.gradinggradeover, + r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt, + s.id AS submissionid, s.authorid + FROM {workshop_assessments} a + JOIN {user} r ON (a.reviewerid = r.id) + JOIN {workshop_submissions} s ON (a.submissionid = s.id) + WHERE a.submissionid $submissionids"; + $reviewers = $DB->get_records_sql($sql, $params); + foreach ($reviewers as $reviewer) { + if (!isset($userinfo[$reviewer->reviewerid])) { + $userinfo[$reviewer->reviewerid] = new stdClass(); + $userinfo[$reviewer->reviewerid]->id = $reviewer->reviewerid; + $userinfo[$reviewer->reviewerid]->firstname = $reviewer->firstname; + $userinfo[$reviewer->reviewerid]->lastname = $reviewer->lastname; + $userinfo[$reviewer->reviewerid]->picture = $reviewer->picture; + $userinfo[$reviewer->reviewerid]->imagealt = $reviewer->imagealt; + } + } + } + + // get current reviewees + list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED); + $params['workshopid'] = $this->id; + $sql = "SELECT a.id AS assessmentid, a.submissionid, a.grade, a.gradinggrade, a.gradinggradeover, + u.id AS reviewerid, + s.id AS submissionid, + e.id AS authorid, e.lastname, e.firstname, e.picture, e.imagealt + FROM {user} u + JOIN {workshop_assessments} a ON (a.reviewerid = u.id) + JOIN {workshop_submissions} s ON (a.submissionid = s.id) + JOIN {user} e ON (s.authorid = e.id) + WHERE u.id $participantids AND s.workshopid = :workshopid"; + $reviewees = $DB->get_records_sql($sql, $params); + foreach ($reviewees as $reviewee) { + if (!isset($userinfo[$reviewee->authorid])) { + $userinfo[$reviewee->authorid] = new stdClass(); + $userinfo[$reviewee->authorid]->id = $reviewee->authorid; + $userinfo[$reviewee->authorid]->firstname = $reviewee->firstname; + $userinfo[$reviewee->authorid]->lastname = $reviewee->lastname; + $userinfo[$reviewee->authorid]->picture = $reviewee->picture; + $userinfo[$reviewee->authorid]->imagealt = $reviewee->imagealt; + } + } + + // get the current grades for assessment + list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED); + $params['workshopid'] = $this->id; + $sql = "SELECT * FROM {workshop_evaluations} WHERE reviewerid $participantids AND workshopid = :workshopid"; + $gradinggrades = $DB->get_records_sql($sql, $params); + + // now populate the final data object to be rendered + $grades = array(); + + foreach ($participants as $participant) { + // set up default (null) values + $grades[$participant->id] = new stdClass; + $grades[$participant->id]->userid = $participant->id; + $grades[$participant->id]->submissionid = null; + $grades[$participant->id]->submissiongrade = null; + $grades[$participant->id]->reviewedby = array(); + $grades[$participant->id]->reviewerof = array(); + $grades[$participant->id]->gradinggrade = null; + $grades[$participant->id]->totalgrade = null; + } + unset($participants); + unset($participant); + + foreach ($submissions as $submission) { + $grades[$submission->authorid]->submissionid = $submission->id; + $grades[$submission->authorid]->submissiontitle = $submission->title; + $grades[$submission->authorid]->submissiongrade = $submission->grade; + $grades[$submission->authorid]->submissiongradeover = $submission->gradeover; + $grades[$submission->authorid]->submissiongradeoverby = $submission->gradeoverby; + } + unset($submissions); + unset($submission); + + foreach($reviewers as $reviewer) { + $info = new stdClass(); + $info->userid = $reviewer->reviewerid; + $info->assessmentid = $reviewer->assessmentid; + $info->submissionid = $reviewer->submissionid; + $info->grade = $reviewer->grade; + $info->gradinggrade = $reviewer->gradinggrade; + $info->gradinggradeover = $reviewer->gradinggradeover; + $grades[$reviewer->authorid]->reviewedby[$reviewer->reviewerid] = $info; + } + unset($reviewers); + unset($reviewer); + + foreach($reviewees as $reviewee) { + $info = new stdClass(); + $info->userid = $reviewee->authorid; + $info->assessmentid = $reviewee->assessmentid; + $info->submissionid = $reviewee->submissionid; + $info->grade = $reviewee->grade; + $info->gradinggrade = $reviewee->gradinggrade; + $info->gradinggradeover = $reviewee->gradinggradeover; + $grades[$reviewee->reviewerid]->reviewerof[$reviewee->authorid] = $info; + } + unset($reviewees); + unset($reviewee); + + foreach ($gradinggrades as $gradinggrade) { + $grades[$gradinggrade->reviewerid]->gradinggrade = $gradinggrade->gradinggrade; + } + + foreach ($grades as $grade) { + $grade->totalgrade = $this->total_grade($grade->submissiongrade, $grade->gradinggrade); + } + + $data = new stdClass(); + $data->grades = $grades; + $data->userinfo = $userinfo; + $data->totalcount = $numofparticipants; + return $data; + } + + /** + * Format the grade for the output + * + * The returned value must not be used for calculations, it is intended for the displaying purposes only + * + * @param float $value the grade value + * @param bool $keepnull whether keep nulls as nulls or return their string representation + * @return string + */ + public function format_grade($value, $keepnull = false) { + if (is_null($value)) { + if ($keepnull) { + return null; + } else { + return get_string('null', 'workshop'); + } + } + $decimalpoints = 1; // todo make the precision configurable + $localized = true; + + return format_float($value, $decimalpoints, $localized); + } + + /** + * Calculate the participant's total grade given the aggregated grades for submission and assessments + * + * todo there will be a setting how to deal with null values (for example no grade for submission) - if + * they are considered as 0 or excluded + * + * @param float|null $grade for submission + * @param float|null $gradinggrade for assessment + * @return float|null + */ + public function total_grade($grade=null, $gradinggrade=null) { + if (is_null($grade) and is_null($gradinggrade)) { + return null; + } + return grade_floatval((float)$grade + (float)$gradinggrade); + } + //////////////////////////////////////////////////////////////////////////////// // Internal methods (implementation details) // //////////////////////////////////////////////////////////////////////////////// diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php index b4c25b8ef5..e22ffcc627 100644 --- a/mod/workshop/renderer.php +++ b/mod/workshop/renderer.php @@ -308,10 +308,10 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base { } /** - * TODO: short description. + * Renders the user plannner tool * - * @param array $plan - * @return TODO + * @param array $plan as returned by {@link workshop::prepare_user_plan()} + * @return string html code to be displayed */ public function user_plan(array $plan) { if (empty($plan)) { @@ -358,10 +358,10 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base { } /** - * TODO: short description. + * Renders the tasks for the single phase in the user plan * - * @param stdClass $tasks - * @return TODO + * @param stdClass $tasks + * @return string html code */ protected function user_plan_tasks(array $tasks) { $out = ''; @@ -392,4 +392,211 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base { } return $out; } + + /** + * Renders the workshop grading report + * + * @param stdClass $data prepared by {@link workshop::prepare_grading_report()} + * @param bool $showauthornames + * @param bool $showreviewernames + * @return string html code + */ + public function grading_report(stdClass $data, $showauthornames, $showreviewernames) { + $grades = $data->grades; + $userinfo = $data->userinfo; + + if (empty($grades)) { + return ''; + } + + $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')); + $table->rowclasses = array(); + $table->colclasses = array('reviewedby', 'peer', 'reviewerof'); + $table->data = array(); + + foreach ($grades as $participant) { + $numofreceived = count($participant->reviewedby); + $numofgiven = count($participant->reviewerof); + + // compute the number of table rows needed to display this participant + if ($numofreceived > 0 and $numofgiven > 0) { + $numoftrs = self::lcm($numofreceived, $numofgiven); + $spanreceived = $numoftrs / $numofreceived; + $spangiven = $numoftrs / $numofgiven; + } elseif ($numofreceived == 0 and $numofgiven > 0) { + $numoftrs = $numofgiven; + $spanreceived = $numoftrs; + $spangiven = $numoftrs / $numofgiven; + } elseif ($numofreceived > 0 and $numofgiven == 0) { + $numoftrs = $numofreceived; + $spanreceived = $numoftrs / $numofreceived; + $spangiven = $numoftrs; + } else { + $numoftrs = 1; + $spanreceived = 1; + $spangiven = 1; + } + + for ($tr = 0; $tr < $numoftrs; $tr++) { + $row = new html_table_row(); + // column #1 - participant - spans over all rows + if ($tr == 0) { + $cell = new html_table_cell(); + $cell->text = $this->grading_report_participant($participant, $userinfo); + $cell->rowspan = $numoftrs; + $row->cells[] = $cell; + } + // column #2 - submission - spans over all rows + if ($tr == 0) { + $cell = new html_table_cell(); + $cell->text = $this->grading_report_submission($participant); + $cell->rowspan = $numoftrs; + $row->cells[] = $cell; + } + // column #3 - received grades + if ($tr % $spanreceived == 0) { + $idx = intval($tr / $spanreceived); + $cell = new html_table_cell(); + $cell->text = $this->grading_report_assessment(self::array_nth($participant->reviewedby, $idx)); + $cell->rowspan = $spanreceived; + $row->cells[] = $cell; + } + // column #4 - total grade for submission + if ($tr == 0) { + $cell = new html_table_cell(); + $cell->text = $participant->submissiongrade; + $cell->rowspan = $numoftrs; + $row->cells[] = $cell; + } + // column #5 - given grades + if ($tr % $spangiven == 0) { + $idx = intval($tr / $spangiven); + $cell = new html_table_cell(); + $cell->text = $this->grading_report_assessment(self::array_nth($participant->reviewerof, $idx)); + $cell->rowspan = $spangiven; + $row->cells[] = $cell; + } + // column #6 - total grade for assessment + if ($tr == 0) { + $cell = new html_table_cell(); + $cell->text = $participant->gradinggrade; + $cell->rowspan = $numoftrs; + $row->cells[] = $cell; + } + // column #7 - total grade for assessment + if ($tr == 0) { + $cell = new html_table_cell(); + $cell->text = $participant->totalgrade; + $cell->rowspan = $numoftrs; + $row->cells[] = $cell; + } + $table->data[] = $row; + } + } + + return $this->output->table($table); + } + + /** + * @param stdClass $participant + * @param array $userinfo + * @return string + */ + protected function grading_report_participant(stdClass $participant, array $userinfo) { + $userid = $participant->userid; + $pic = new moodle_user_picture(); + $pic->user = $userinfo[$userid]; + $pic->courseid = $this->page->course->id; + $pic->url = true; + $pic->size = 35; + + $out = $this->output->user_picture($pic); + $out .= $this->output->output_tag('span', '', fullname($userinfo[$userid])); + + return $out; + } + + /** + * @param stdClass $participant + * @return string + */ + protected function grading_report_submission(stdClass $participant) { + if (is_null($participant->submissionid)) { + $out = $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info'); + } else { + $out = $this->output->container(format_string($participant->submissiontitle), 'title'); + } + + return $out; + } + + /** + * @todo grade formatting (decimals) + * @param stdClass|null $assessment + * @return string + */ + protected function grading_report_assessment($assessment) { + if (is_null($assessment)) { + return get_string('null', 'workshop'); + } + $a = new stdClass(); + $a->grade = is_null($assessment->grade) ? get_string('null', 'workshop') : $assessment->grade; + $a->gradinggrade = is_null($assessment->gradinggrade) ? get_string('null', 'workshop') : $assessment->gradinggrade; + if (is_null($assessment->gradinggradeover)) { + $grade = get_string('formatpeergrade', 'workshop', $a); + } else { + $a->gradinggradeover = $assessment->gradinggradeover; + $grade = get_string('formatpeergradeover', 'workshop', $a); + } + + return $grade; + } + + + /** + * Helper function returning the greatest common divisor + * + * @param int $a + * @param int $b + * @return int + */ + protected static function gcd($a, $b) { + return ($b == 0) ? ($a):(self::gcd($b, $a % $b)); + } + + /** + * Helper function returning the least common multiple + * + * @param int $a + * @param int $b + * @return int + */ + protected static function lcm($a, $b) { + return ($a / self::gcd($a,$b)) * $b; + } + + /** + * Helper function returning the n-th item of the array + * + * @param array $a + * @param int $n from 0 to m, where m is th number of items in the array + * @return mixed the $n-th element of $a + */ + protected static function array_nth(array $a, $n) { + $keys = array_keys($a); + if ($n < 0 or $n > count($keys) - 1) { + return null; + } + $key = $keys[$n]; + return $a[$key]; + } + } diff --git a/mod/workshop/styles.php b/mod/workshop/styles.php index 223a274911..89841d8532 100644 --- a/mod/workshop/styles.php +++ b/mod/workshop/styles.php @@ -325,3 +325,19 @@ .mod-workshop .assessmentform .description { margin: 0px 1em; } + +/** + * Grading report + */ +.mod-workshop .grading-report { + width: 90%; + margin: 1em auto 1em auto; + font-size: 80%; + border: 1px solid #ddd; +} + +.mod-workshop .grading-report td { + vertical-align: top; + border: 1px solid #ddd; +} + diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 889dd9f3d8..a8cfc14177 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -107,7 +107,7 @@ case workshop::PHASE_SUBMISSION: if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) { $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); echo $OUTPUT->box_start('generalbox allsubmissions'); - if (! $submissions = $workshop->get_submissions('all', false)) { + if (! $submissions = $workshop->get_submissions('all')) { echo $OUTPUT->container(get_string('nosubmissions', 'workshop'), 'nosubmissions'); } foreach ($submissions as $submission) { @@ -159,140 +159,24 @@ case workshop::PHASE_EVALUATION: $pagingvar = 'page'; $page = optional_param($pagingvar, 0, PARAM_INT); - if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { - $showauthornames = has_capability('mod/workshop:viewauthornames', $PAGE->context); - $showreviewernames = has_capability('mod/workshop:viewreviewernames', $PAGE->context); - // todo this is very similar to what allocation/manual/lib.php does - refactoring expectable - - // fetch the list of ids of all workshop participants - this may get really long so fetch just id - $participants = get_users_by_capability($PAGE->context, array('mod/workshop:submit', 'mod/workshop:peerassess'), - 'u.id', 'u.lastname,u.firstname,u.id', '', '', '', '', false, false, true); - - $numofparticipants = count($participants); // we will need later for the pagination - - // slice the list of participants according to the current page - $participants = array_slice($participants, $page * workshop::PERPAGE, workshop::PERPAGE, true); - - // this will hold the information needed to display user names and pictures - $userinfo = $DB->get_records_list('user', 'id', array_keys($participants), '', 'id,lastname,firstname,picture,imagealt'); - - // load the participants' submissions - $submissions = $workshop->get_submissions(array_keys($participants), false); - foreach ($submissions as $submission) { - if (!isset($userinfo[$submission->authorid])) { - $userinfo[$submission->authorid] = new stdClass(); - $userinfo[$submission->authorid]->id = $submission->authorid; - $userinfo[$submission->authorid]->firstname = $submission->authorfirstname; - $userinfo[$submission->authorid]->lastname = $submission->authorlastname; - $userinfo[$submission->authorid]->picture = $submission->authorpicture; - $userinfo[$submission->authorid]->imagealt = $submission->authorimagealt; - } - if (!isset($userinfo[$submission->gradeoverby])) { - $userinfo[$submission->gradeoverby] = new stdClass(); - $userinfo[$submission->gradeoverby]->id = $submission->gradeoverby; - $userinfo[$submission->gradeoverby]->firstname = $submission->overfirstname; - $userinfo[$submission->gradeoverby]->lastname = $submission->overlastname; - $userinfo[$submission->gradeoverby]->picture = $submission->overpicture; - $userinfo[$submission->gradeoverby]->imagealt = $submission->overimagealt; - } - } - - // get current reviewers - $reviewers = array(); - if ($submissions) { - list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED); - $sql = "SELECT a.id AS assessmentid, a.submissionid, - r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt, - s.id AS submissionid, s.authorid - FROM {workshop_assessments} a - JOIN {user} r ON (a.reviewerid = r.id) - JOIN {workshop_submissions} s ON (a.submissionid = s.id) - WHERE a.submissionid $submissionids"; - $reviewers = $DB->get_records_sql($sql, $params); - foreach ($reviewers as $reviewer) { - if (!isset($userinfo[$reviewer->reviewerid])) { - $userinfo[$reviewer->reviewerid] = new stdClass(); - $userinfo[$reviewer->reviewerid]->id = $reviewer->reviewerid; - $userinfo[$reviewer->reviewerid]->firstname = $reviewer->firstname; - $userinfo[$reviewer->reviewerid]->lastname = $reviewer->lastname; - $userinfo[$reviewer->reviewerid]->picture = $reviewer->picture; - $userinfo[$reviewer->reviewerid]->imagealt = $reviewer->imagealt; - } - } - } - - // get current reviewees - list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED); - $params['workshopid'] = $workshop->id; - $sql = "SELECT a.id AS assessmentid, a.submissionid, - u.id AS reviewerid, - s.id AS submissionid, - e.id AS revieweeid, e.lastname, e.firstname, e.picture, e.imagealt - FROM {user} u - JOIN {workshop_assessments} a ON (a.reviewerid = u.id) - JOIN {workshop_submissions} s ON (a.submissionid = s.id) - JOIN {user} e ON (s.authorid = e.id) - WHERE u.id $participantids AND s.workshopid = :workshopid"; - $reviewees = $DB->get_records_sql($sql, $params); - foreach ($reviewees as $reviewee) { - if (!isset($userinfo[$reviewee->revieweeid])) { - $userinfo[$reviewee->revieweeid] = new stdClass(); - $userinfo[$reviewee->revieweeid]->id = $reviewee->revieweeid; - $userinfo[$reviewee->revieweeid]->firstname = $reviewee->firstname; - $userinfo[$reviewee->revieweeid]->lastname = $reviewee->lastname; - $userinfo[$reviewee->revieweeid]->picture = $reviewee->picture; - $userinfo[$reviewee->revieweeid]->imagealt = $reviewee->imagealt; - } - } - - // get the current grades for assessment - list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED); - $params['workshopid'] = $workshop->id; - $sql = "SELECT * FROM {workshop_evaluations} WHERE reviewerid $participantids AND workshopid = :workshopid"; - $gradinggrades = $DB->get_records_sql($sql, $params); - - // now populate the final data object to be rendered - $grades = array(); - - foreach ($participants as $participant) { - // set up default (null) values - $grades[$participant->id] = new stdClass; - $grades[$participant->id]->userid = $participant->id; - $grades[$participant->id]->submissionid = null; - $grades[$participant->id]->reviewedby = array(); - $grades[$participant->id]->reviewerof = array(); - $grades[$participant->id]->gradinggrade = null; - } - unset($participants); - - foreach ($submissions as $submission) { - $grades[$submission->authorid]->submissionid = $submission->id; - $grades[$submission->authorid]->submissiontitle = $submission->title; - $grades[$submission->authorid]->submissiongrade = $submission->grade; - $grades[$submission->authorid]->submissiongradeover = $submission->gradeover; - $grades[$submission->authorid]->submissiongradeoverby = $submission->gradeoverby; - } - unset($submissions); - - foreach($reviewers as $reviewer) { - $grades[$reviewer->authorid]->reviewedby[$reviewer->reviewerid] = $reviewer->assessmentid; - } - unset($reviewers); - - foreach($reviewees as $reviewee) { - $grades[$reviewee->reviewerid]->reviewerof[$reviewee->revieweeid] = $reviewee->assessmentid; - } - unset($reviewees); - - foreach ($gradinggrades as $gradinggrade) { - $grades[$gradinggrade->reviewerid]->gradinggrade = $gradinggrade->gradinggrade; - } - - // we have all data, let us pass it to the renderer and return the output - - print_object($grades); die(); // DONOTCOMMIT - break; + $data = $workshop->prepare_grading_report($PAGE->context, $USER->id, $page); + if ($data) { + $showauthornames = has_capability('mod/workshop:viewauthornames', $PAGE->context); + $showreviewernames = has_capability('mod/workshop:viewreviewernames', $PAGE->context); + + // prepare paging bar + $pagingbar = new moodle_paging_bar(); + $pagingbar->totalcount = $data->totalcount; + $pagingbar->page = $page; + $pagingbar->perpage = workshop::PERPAGE; + $pagingbar->baseurl = $PAGE->url; + $pagingbar->pagevar = $pagingvar; + + echo $OUTPUT->paging_bar($pagingbar); + echo $wsoutput->grading_report($data, $showauthornames, $showreviewernames); + echo $OUTPUT->paging_bar($pagingbar); } + break; case workshop::PHASE_CLOSED: default: }