MDL-27550 workshop: display the feedback for the submission author when the workshop...
authorDavid Mudrak <david@moodle.com>
Wed, 27 Jul 2011 17:15:41 +0000 (19:15 +0200)
committerDavid Mudrak <david@moodle.com>
Tue, 2 Aug 2011 21:33:32 +0000 (23:33 +0200)
The method user_picture::fields() was not available when these SQL
statements were originally written. Now instead of hard-coding the list
of returned fields, the user_picture is asked for the list.

Together with this change, methods workshop::get_submission_by_id()
and workshop::get_submission_by_author() now return the information
about the user who provided the feedback and overwrote the grade.

mod/workshop/lang/en/workshop.php
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/styles.css
mod/workshop/submission.php
mod/workshop/view.php

index 9031486..3417d5e 100644 (file)
@@ -114,6 +114,7 @@ $string['examplesmode'] = 'Mode of examples assessment';
 $string['examplesubmissions'] = 'Example submissions';
 $string['examplesvoluntary'] = 'Assessment of example submission is voluntary';
 $string['feedbackauthor'] = 'Feedback for the author';
+$string['feedbackby'] = 'Feedback by {$a}';
 $string['feedbackreviewer'] = 'Feedback for the reviewer';
 $string['formataggregatedgrade'] = '{$a->grade}';
 $string['formataggregatedgradeover'] = '<del>{$a->grade}</del><br /><ins>{$a->over}</ins>';
index 9aeaa83..11d6aaa 100644 (file)
@@ -489,16 +489,15 @@ class workshop {
     public function get_submissions($authorid='all') {
         global $DB;
 
-        $sql = 'SELECT s.id, s.workshopid, s.example, s.authorid, s.timecreated, s.timemodified,
+        $authorfields      = user_picture::fields('u', null, 'authoridx', 'author');
+        $gradeoverbyfields = user_picture::fields('t', null, 'gradeoverbyx', 'over');
+        $sql = "SELECT s.id, s.workshopid, s.example, s.authorid, s.timecreated, s.timemodified,
                        s.title, s.grade, s.gradeover, s.gradeoverby, s.published,
-                       u.lastname AS authorlastname, u.firstname AS authorfirstname,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail,
-                       t.lastname AS overlastname, t.firstname AS overfirstname,
-                       t.picture AS overpicture, t.imagealt AS overimagealt, t.email AS overemail
+                       $authorfields, $gradeoverbyfields
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
              LEFT JOIN {user} t ON (s.gradeoverby = t.id)
-                 WHERE s.example = 0 AND s.workshopid = :workshopid';
+                 WHERE s.example = 0 AND s.workshopid = :workshopid";
         $params = array('workshopid' => $this->id);
 
         if ('all' === $authorid) {
@@ -511,7 +510,7 @@ class workshop {
             // $authorid is empty
             return array();
         }
-        $sql .= ' ORDER BY u.lastname, u.firstname';
+        $sql .= " ORDER BY u.lastname, u.firstname";
 
         return $DB->get_records_sql($sql, $params);
     }
@@ -527,12 +526,13 @@ class workshop {
 
         // 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, u.email AS authoremail
+        $authorfields      = user_picture::fields('u', null, 'authoridx', 'author');
+        $gradeoverbyfields = user_picture::fields('g', null, 'gradeoverbyx', 'gradeoverby');
+        $sql = "SELECT s.*, $authorfields, $gradeoverbyfields
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
-                 WHERE s.example = 0 AND s.workshopid = :workshopid AND s.id = :id';
+             LEFT JOIN {user} g ON (s.gradeoverby = g.id)
+                 WHERE s.example = 0 AND s.workshopid = :workshopid AND s.id = :id";
         $params = array('workshopid' => $this->id, 'id' => $id);
         return $DB->get_record_sql($sql, $params, MUST_EXIST);
     }
@@ -549,12 +549,13 @@ class workshop {
         if (empty($authorid)) {
             return false;
         }
-        $sql = 'SELECT s.*,
-                       u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail
+        $authorfields      = user_picture::fields('u', null, 'authoridx', 'author');
+        $gradeoverbyfields = user_picture::fields('g', null, 'gradeoverbyx', 'gradeoverby');
+        $sql = "SELECT s.*, $authorfields, $gradeoverbyfields
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
-                 WHERE s.example = 0 AND s.workshopid = :workshopid AND s.authorid = :authorid';
+             LEFT JOIN {user} g ON (s.gradeoverby = g.id)
+                 WHERE s.example = 0 AND s.workshopid = :workshopid AND s.authorid = :authorid";
         $params = array('workshopid' => $this->id, 'authorid' => $authorid);
         return $DB->get_record_sql($sql, $params);
     }
@@ -567,10 +568,10 @@ class workshop {
     public function get_published_submissions($orderby='finalgrade DESC') {
         global $DB;
 
+        $authorfields = user_picture::fields('u', null, 'authoridx', 'author');
         $sql = "SELECT s.id, s.authorid, s.timecreated, s.timemodified,
                        s.title, s.grade, s.gradeover, COALESCE(s.gradeover,s.grade) AS finalgrade,
-                       u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail
+                       $authorfields
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
                  WHERE s.example = 0 AND s.workshopid = :workshopid AND s.published = 1
@@ -2813,3 +2814,74 @@ class workshop_grading_report implements renderable {
         return $this->options;
     }
 }
+
+
+/**
+ * Base class for renderable feedback for author and feedback for reviewer
+ */
+abstract class workshop_feedback {
+
+    /** @var stdClass the user info */
+    protected $provider = null;
+
+    /** @var string the feedback text */
+    protected $content = null;
+
+    /** @var int format of the feedback text */
+    protected $format = null;
+
+    /**
+     * @return stdClass the user info
+     */
+    public function get_provider() {
+
+        if (is_null($this->provider)) {
+            throw new coding_exception('Feedback provider not set');
+        }
+
+        return $this->provider;
+    }
+
+    /**
+     * @return string the feedback text
+     */
+    public function get_content() {
+
+        if (is_null($this->content)) {
+            throw new coding_exception('Feedback content not set');
+        }
+
+        return $this->content;
+    }
+
+    /**
+     * @return int format of the feedback text
+     */
+    public function get_format() {
+
+        if (is_null($this->format)) {
+            throw new coding_exception('Feedback text format not set');
+        }
+
+        return $this->format;
+    }
+}
+
+
+/**
+ * Renderable feedback for the author of submission
+ */
+class workshop_feedback_author extends workshop_feedback implements renderable {
+
+    /**
+     * Extracts feedback from the given submission record
+     *
+     * @param stdClass $submission record as returned by {@see self::get_submission_by_id()}
+     */
+    public function __construct(stdClass $submission) {
+
+        $this->provider = user_picture::unalias($submission, null, 'gradeoverbyx', 'gradeoverby');
+        $this->content  = $submission->feedbackauthor;
+        $this->format   = $submission->feedbackauthorformat;
+    }
+}
index 1b1333e..22b2419 100644 (file)
@@ -490,6 +490,30 @@ class mod_workshop_renderer extends plugin_renderer_base {
         return html_writer::table($table);
     }
 
+    /**
+     * Renders the feedback for the author of the submission
+     *
+     * @param workshop_feedback_author $feedback
+     * @return string HTML
+     */
+    protected function render_workshop_feedback_author(workshop_feedback_author $feedback) {
+
+        $o  = '';    // output HTML code
+        $o .= $this->output->container_start('feedback feedbackforauthor');
+        $o .= $this->output->container_start('header');
+        $o .= $this->output->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title');
+
+        $userpic = $this->output->user_picture($feedback->get_provider(), array('courseid' => $this->page->course->id, 'size' => 32));
+        $o .= $this->output->container($userpic, 'picture');
+        $o .= $this->output->container_end(); // end of header
+
+        $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
+
+        return $o;
+    }
 
     ////////////////////////////////////////////////////////////////////////////
     // Internal rendering helper methods
index 22c4851..e160e51 100644 (file)
@@ -45,7 +45,8 @@
 
 .path-mod-workshop .submission-summary.anonymous .title,
 .path-mod-workshop .submission-summary.anonymous .author,
-.path-mod-workshop .submission-summary.anonymous .userdate {
+.path-mod-workshop .submission-summary.anonymous .userdate,
+.path-mod-workshop .submission-summary.anonymous .grade-status {
     margin: 0px 0px 0px 5px;
 }
 
     vertical-align: top;
 }
 
+/**
+ * Feedback
+ */
+.path-mod-workshop .feedback {
+    border: 1px solid #ddd;
+    margin: 0px auto 1em auto;
+    width: 80%;
+}
+
+.path-mod-workshop .feedback .header {
+    position: relative;
+    background-color: #ddd;
+    padding: 3px;
+    min-height: 35px;
+}
+
+.path-mod-workshop .feedback .header .title {
+    margin: 0px 0px 0px 40px;
+}
+
+.path-mod-workshop .feedback .header .picture {
+    position: absolute;
+    top: 3px;
+    left: 3px;
+}
+
+.path-mod-workshop .feedback .content {
+    padding: 5px 10px;
+}
+
 /**
  * Misc
  */
index 2932c90..af0b98e 100644 (file)
@@ -272,6 +272,12 @@ if ($submission->id and !$edit and !$isreviewer and $canallocate and $workshop->
     echo $output->single_button($url, get_string('assess', 'workshop'), 'post');
 }
 
+if (($workshop->phase == workshop::PHASE_CLOSED) and ($ownsubmission or $canviewall)) {
+    if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
+        echo $output->render(new workshop_feedback_author($submission));
+    }
+}
+
 // and possibly display the submission's review(s)
 
 if ($isreviewer) {
index b733ce9..561b64f 100644 (file)
@@ -493,6 +493,11 @@ case workshop::PHASE_CLOSED:
             echo $output->container(get_string('noyoursubmission', 'workshop'));
         }
         echo $output->box_end();
+
+        if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
+            echo $output->render(new workshop_feedback_author($submission));
+        }
+
         print_collapsible_region_end();
     }
     if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) {