Skip to content

Commit

Permalink
MDL-39173 Assign - Enable comments for blind marking assignments (ano…
Browse files Browse the repository at this point in the history
…nymous ones)
  • Loading branch information
samchaffee authored and Damyon Wiese committed Apr 19, 2013
1 parent 3a8c438 commit 0399580
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
1 change: 1 addition & 0 deletions comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ public function get_comments($page = '') {
$c->time = userdate($c->timecreated, $c->strftimeformat);
$c->content = format_text($c->content, $c->format, $formatoptions);
$c->avatar = $OUTPUT->user_picture($u, array('size'=>18));
$c->userid = $u->id;

$candelete = $this->can_delete($c->id);
if (($USER->id == $u->id) || !empty($candelete)) {
Expand Down
66 changes: 66 additions & 0 deletions mod/assign/submission/comments/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,72 @@ function assignsubmission_comments_comment_permissions(stdClass $options) {
return array('post' => true, 'view' => true);
}

/**
* Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking.
*
* @param array $comments
* @param stdClass $options
* @return array
* @throws comment_exception
*/
function assignsubmission_comments_comment_display($comments, $options) {
global $CFG, $DB, $USER, $OUTPUT;

if ($options->commentarea != 'submission_comments' &&
$options->commentarea != 'submission_comments_upgrade') {
throw new comment_exception('invalidcommentarea');
}
if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) {
throw new comment_exception('invalidcommentitemid');
}
$context = $options->context;
$cm = $options->cm;
$course = $options->courseid;

require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assignment = new assign($context, $cm, $course);

if ($assignment->get_instance()->id != $submission->assignment) {
throw new comment_exception('invalidcontext');
}

if ($assignment->is_blind_marking() && !empty($comments)) {
// Blind marking is being used, may need to map unique anonymous ids to the comments.
$usermappings = array();
$hiddenuserstr = trim(get_string('hiddenuser', 'assign'));
$guestuser = guest_user();

foreach ($comments as $comment) {
if (($USER->id != $comment->userid) && !has_capability('mod/assign:grade', $assignment->get_context(), $comment->userid)) {
// Anonymize if the logged in user is not the commenter and the commenter does not have the grading capability.
if (empty($usermappings[$comment->userid])) {
// The blind-marking information for this commenter has not been generated; do so now.
$anonid = $assignment->get_uniqueid_for_user($comment->userid);
$commenter = new stdClass();
$commenter->firstname = $hiddenuserstr;
$commenter->lastname = $anonid;
$commenter->picture = 0;
$commenter->id = $guestuser->id;
$commenter->email = $guestuser->email;
$commenter->imagealt = $guestuser->imagealt;

// Temporarily store blind-marking information for use in later comments if necessary.
$usermappings[$comment->userid]->fullname = fullname($commenter);
$usermappings[$comment->userid]->avatar = $OUTPUT->user_picture($commenter,
array('size'=>18, 'link' => false));
}

// Set blind-marking information for this comment.
$comment->fullname = $usermappings[$comment->userid]->fullname;
$comment->avatar = $usermappings[$comment->userid]->avatar;
$comment->profileurl = null;
}
}
}

return $comments;
}

/**
* Callback to force the userid for all comments to be the userid of the submission and NOT the global $USER->id. This
* is required by the upgrade code. Note the comment area is used to identify upgrades.
Expand Down
13 changes: 0 additions & 13 deletions mod/assign/submission/comments/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,4 @@ public function upgrade(context $oldcontext,
public function allow_submissions() {
return false;
}

/**
* If blind marking is enabled then disable this plugin (it shows names)
*
* @return bool
*/
public function is_enabled() {
if ($this->assignment->has_instance() && $this->assignment->is_blind_marking()) {
return false;
}
return parent::is_enabled();
}

}

0 comments on commit 0399580

Please sign in to comment.