Permalink
Browse files

MDL-39173 Assign - Enable comments for blind marking assignments (ano…

…nymous ones)
  • Loading branch information...
1 parent 3a8c438 commit 0399580003da8693201aab1284dca743e37d9757 @sam-moodle sam-moodle committed with damyon Apr 19, 2013
Showing with 67 additions and 13 deletions.
  1. +1 −0 comment/lib.php
  2. +66 −0 mod/assign/submission/comments/lib.php
  3. +0 −13 mod/assign/submission/comments/locallib.php
View
1 comment/lib.php
@@ -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)) {
View
66 mod/assign/submission/comments/lib.php
@@ -107,6 +107,72 @@ function assignsubmission_comments_comment_permissions(stdClass $options) {
}
/**
+ * 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.
*
View
13 mod/assign/submission/comments/locallib.php
@@ -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.