/** * 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 setasksubmission_comments_comment_display($comments, $options) { global $CFG, $DB, $USER; if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') { throw new comment_exception('invalidcommentarea'); } if (!($submission = $DB->get_record('setask_submission', array('id' => $options->itemid)))) { throw new comment_exception('invalidcommentitemid'); } $context = $options->context; $cm = $options->cm; $course = $options->courseid; require_once $CFG->dirroot . '/mod/setask/locallib.php'; $setaskment = new setask($context, $cm, $course); if ($setaskment->get_instance()->id != $submission->setaskment) { throw new comment_exception('invalidcontext'); } if ($setaskment->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', 'setask')); $guestuser = guest_user(); foreach ($comments as $comment) { // Anonymize the comments. if (empty($usermappings[$comment->userid])) { // The blind-marking information for this commenter has not been generated; do so now. $anonid = $setaskment->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 = $setaskment->get_renderer()->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; }