MDL-27550 workshop: display the feedback for the submission reviewer when the worksho...
authorDavid Mudrak <david@moodle.com>
Thu, 28 Jul 2011 20:18:45 +0000 (22:18 +0200)
committerDavid Mudrak <david@moodle.com>
Tue, 2 Aug 2011 21:33:32 +0000 (23:33 +0200)
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/submission.php
mod/workshop/view.php

index a409d51..f0c0c36 100644 (file)
@@ -771,14 +771,16 @@ class workshop {
 
         $reviewerfields = user_picture::fields('reviewer', null, 'revieweridx', 'reviewer');
         $authorfields   = user_picture::fields('author', null, 'authorid', 'author');
+        $overbyfields   = user_picture::fields('overby', null, 'gradinggradeoverbyx', 'overby');
         $sql = "SELECT a.id, a.submissionid, a.reviewerid, a.timecreated, a.timemodified,
                        a.grade, a.gradinggrade, a.gradinggradeover, a.gradinggradeoverby,
-                       $reviewerfields, $authorfields,
+                       $reviewerfields, $authorfields, $overbyfields,
                        s.title
                   FROM {workshop_assessments} a
             INNER JOIN {user} reviewer ON (a.reviewerid = reviewer.id)
             INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id)
             INNER JOIN {user} author ON (s.authorid = author.id)
+             LEFT JOIN {user} overby ON (a.gradinggradeoverby = overby.id)
                  WHERE s.workshopid = :workshopid AND s.example = 0
               ORDER BY reviewer.lastname, reviewer.firstname";
         $params = array('workshopid' => $this->id);
@@ -797,11 +799,13 @@ class workshop {
 
         $reviewerfields = user_picture::fields('reviewer', null, 'revieweridx', 'reviewer');
         $authorfields   = user_picture::fields('author', null, 'authorid', 'author');
-        $sql = "SELECT a.*, s.title, $reviewerfields, $authorfields
+        $overbyfields   = user_picture::fields('overby', null, 'gradinggradeoverbyx', 'overby');
+        $sql = "SELECT a.*, s.title, $reviewerfields, $authorfields, $overbyfields
                   FROM {workshop_assessments} a
             INNER JOIN {user} reviewer ON (a.reviewerid = reviewer.id)
             INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id)
             INNER JOIN {user} author ON (s.authorid = author.id)
+             LEFT JOIN {user} overby ON (a.gradinggradeoverby = overby.id)
                  WHERE a.id = :id AND s.workshopid = :workshopid";
         $params = array('id' => $id, 'workshopid' => $this->id);
 
@@ -820,11 +824,13 @@ class workshop {
 
         $reviewerfields = user_picture::fields('reviewer', null, 'revieweridx', 'reviewer');
         $authorfields   = user_picture::fields('author', null, 'authorid', 'author');
-        $sql = "SELECT a.*, s.title, $reviewerfields, $authorfields
+        $overbyfields   = user_picture::fields('overby', null, 'gradinggradeoverbyx', 'overby');
+        $sql = "SELECT a.*, s.title, $reviewerfields, $authorfields, $overbyfields
                   FROM {workshop_assessments} a
             INNER JOIN {user} reviewer ON (a.reviewerid = reviewer.id)
             INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id AND s.example = 0)
             INNER JOIN {user} author ON (s.authorid = author.id)
+             LEFT JOIN {user} overby ON (a.gradinggradeoverby = overby.id)
                  WHERE s.id = :sid AND reviewer.id = :rid AND s.workshopid = :workshopid";
         $params = array('sid' => $submissionid, 'rid' => $reviewerid, 'workshopid' => $this->id);
 
@@ -841,10 +847,12 @@ class workshop {
         global $DB;
 
         $reviewerfields = user_picture::fields('reviewer', null, 'revieweridx', 'reviewer');
-        $sql = "SELECT a.*, s.title, $reviewerfields
+        $overbyfields   = user_picture::fields('overby', null, 'gradinggradeoverbyx', 'overby');
+        $sql = "SELECT a.*, s.title, $reviewerfields, $overbyfields
                   FROM {workshop_assessments} a
             INNER JOIN {user} reviewer ON (a.reviewerid = reviewer.id)
             INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id)
+             LEFT JOIN {user} overby ON (a.gradinggradeoverby = overby.id)
                  WHERE s.example = 0 AND s.id = :submissionid AND s.workshopid = :workshopid
               ORDER BY reviewer.lastname, reviewer.firstname, reviewer.id";
         $params = array('submissionid' => $submissionid, 'workshopid' => $this->id);
@@ -863,13 +871,15 @@ class workshop {
 
         $reviewerfields = user_picture::fields('reviewer', null, 'revieweridx', 'reviewer');
         $authorfields   = user_picture::fields('author', null, 'authorid', 'author');
-        $sql = "SELECT a.*, $reviewerfields, $authorfields,
+        $overbyfields   = user_picture::fields('overby', null, 'gradinggradeoverbyx', 'overby');
+        $sql = "SELECT a.*, $reviewerfields, $authorfields, $overbyfields,
                        s.id AS submissionid, s.title AS submissiontitle, s.timecreated AS submissioncreated,
                        s.timemodified AS submissionmodified
                   FROM {workshop_assessments} a
             INNER JOIN {user} reviewer ON (a.reviewerid = reviewer.id)
             INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id)
             INNER JOIN {user} author ON (s.authorid = author.id)
+             LEFT JOIN {user} overby ON (a.gradinggradeoverby = overby.id)
                  WHERE s.example = 0 AND reviewer.id = :reviewerid AND s.workshopid = :workshopid";
         $params = array('reviewerid' => $reviewerid, 'workshopid' => $this->id);
 
@@ -3040,3 +3050,22 @@ class workshop_feedback_author extends workshop_feedback implements renderable {
         $this->format   = $submission->feedbackauthorformat;
     }
 }
+
+
+/**
+ * Renderable feedback for the reviewer
+ */
+class workshop_feedback_reviewer extends workshop_feedback implements renderable {
+
+    /**
+     * Extracts feedback from the given assessment record
+     *
+     * @param stdClass $assessment record as returned by eg {@see self::get_assessment_by_id()}
+     */
+    public function __construct(stdClass $assessment) {
+
+        $this->provider = user_picture::unalias($assessment, null, 'gradinggradeoverbyx', 'overby');
+        $this->content  = $assessment->feedbackreviewer;
+        $this->format   = $assessment->feedbackreviewerformat;
+    }
+}
index b500d12..2dd91bc 100644 (file)
@@ -497,6 +497,26 @@ class mod_workshop_renderer extends plugin_renderer_base {
      * @return string HTML
      */
     protected function render_workshop_feedback_author(workshop_feedback_author $feedback) {
+        return $this->helper_render_feedback($feedback);
+    }
+
+    /**
+     * Renders the feedback for the reviewer of the submission
+     *
+     * @param workshop_feedback_reviewer $feedback
+     * @return string HTML
+     */
+    protected function render_workshop_feedback_reviewer(workshop_feedback_reviewer $feedback) {
+        return $this->helper_render_feedback($feedback);
+    }
+
+    /**
+     * Helper method to rendering feedback
+     *
+     * @param workshop_feedback_author|workshop_feedback_reviewer $feedback
+     * @return string HTML
+     */
+    private function helper_render_feedback($feedback) {
 
         $o  = '';    // output HTML code
         $o .= $this->output->container_start('feedback feedbackforauthor');
@@ -510,7 +530,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
         $content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true));
         $o .= $this->output->container($content, 'content');
 
-        $o .= $this->output->container_end(); // end of submission-full
+        $o .= $this->output->container_end();
 
         return $o;
     }
index 94d9a76..cc79ed8 100644 (file)
@@ -305,6 +305,12 @@ if ($isreviewer) {
     }
 
     echo $output->render($assessment);
+
+    if ($workshop->phase == workshop::PHASE_CLOSED) {
+        if (strlen(trim($userassessment->feedbackreviewer)) > 0) {
+            echo $output->render(new workshop_feedback_reviewer($userassessment));
+        }
+    }
 }
 
 if (has_capability('mod/workshop:viewallassessments', $workshop->context) or ($ownsubmission and $workshop->assessments_available())) {
@@ -324,11 +330,17 @@ if (has_capability('mod/workshop:viewallassessments', $workshop->context) or ($o
             'showform'      => !is_null($assessment->grade),
             'showweight'    => true,
         );
-        $assessment = $workshop->prepare_assessment($assessment, $mform, $options);
+        $displayassessment = $workshop->prepare_assessment($assessment, $mform, $options);
         if ($canoverride) {
-            $assessment->add_action($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'));
+            $displayassessment->add_action($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'));
+        }
+        echo $output->render($displayassessment);
+
+        if ($workshop->phase == workshop::PHASE_CLOSED and has_capability('mod/workshop:viewallassessments', $workshop->context)) {
+            if (strlen(trim($assessment->feedbackreviewer)) > 0) {
+                echo $output->render(new workshop_feedback_reviewer($assessment));
+            }
         }
-        echo $output->render($assessment);
     }
 }
 
index 561b64f..999894d 100644 (file)
@@ -540,6 +540,10 @@ case workshop::PHASE_CLOSED:
             echo $output->box_start('generalbox assessment-summary' . $class);
             echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
             echo $output->box_end();
+
+            if (strlen(trim($assessment->feedbackreviewer)) > 0) {
+                echo $output->render(new workshop_feedback_reviewer($assessment));
+            }
         }
         print_collapsible_region_end();
     }