Skip to content

Commit

Permalink
MDL-27550 workshop: display the feedback for the submission author wh…
Browse files Browse the repository at this point in the history
…en the workshop is closed

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.
  • Loading branch information
mudrd8mz committed Aug 2, 2011
1 parent ca3e8e9 commit 0dfb4ba
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 18 deletions.
1 change: 1 addition & 0 deletions mod/workshop/lang/en/workshop.php
Expand Up @@ -114,6 +114,7 @@
$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>';
Expand Down
106 changes: 89 additions & 17 deletions mod/workshop/locallib.php
Expand Up @@ -489,16 +489,15 @@ public function get_allocations() {
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) {
Expand All @@ -511,7 +510,7 @@ public function get_submissions($authorid='all') {
// $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);
}
Expand All @@ -527,12 +526,13 @@ public function get_submission_by_id($id) {

// 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);
}
Expand All @@ -549,12 +549,13 @@ public function get_submission_by_author($authorid) {
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);
}
Expand All @@ -567,10 +568,10 @@ public function get_submission_by_author($authorid) {
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
Expand Down Expand Up @@ -2813,3 +2814,74 @@ public function get_options() {
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;
}
}
24 changes: 24 additions & 0 deletions mod/workshop/renderer.php
Expand Up @@ -490,6 +490,30 @@ protected function render_workshop_grading_report(workshop_grading_report $gradi
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
Expand Down
33 changes: 32 additions & 1 deletion mod/workshop/styles.css
Expand Up @@ -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;
}

Expand Down Expand Up @@ -395,6 +396,36 @@
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
*/
Expand Down
6 changes: 6 additions & 0 deletions mod/workshop/submission.php
Expand Up @@ -272,6 +272,12 @@
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) {
Expand Down
5 changes: 5 additions & 0 deletions mod/workshop/view.php
Expand Up @@ -493,6 +493,11 @@
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)) {
Expand Down

0 comments on commit 0dfb4ba

Please sign in to comment.